import { ElLoading } from 'element-plus'
import { Loading } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
let loading = null
import { Type } from './types'
export const openLoading = (options = {}) => {
  const text = options.text || '加载中'
  loading = ElLoading.service({
    lock: true,
    text: text,
  })
}
export const closeLoading = () => {
  loading && loading.close()
}
export const showMessage = (message: String, type: string, showClose: Boolean = true, center: Boolean = true) => {
  return ElMessage({
    message: message,
    grouping: true,
    type: type,
    showClose: showClose,
    center: center,
  })
}
export const showMessageConfirm = (
  title: String,
  message: String,
  confirmButtonText: String = '确认',
  cancelButtonText: String = '取消',
  confirmFunx,
  errorFunc,
) => {
  ElMessageBox.confirm(message, title, {
    confirmButtonText: confirmButtonText,
    cancelButtonText: cancelButtonText,
    type: 'warning',
  })
    .then(() => {
      confirmFunx && confirmFunx()
    })
    .catch(() => {
      errorFunc && errorFunc()
    })
}
